<%@ page import="weaver.general.BaseBean" %>
<%@ page import="cn.hutool.json.JSONUtil" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>RoleReturnJsp===>Title</title>
</head>
<body>
<%!
    public  StringBuilder distainStr(StringBuilder cjRHrmresouce){
        //风险系统 字段待确认 已确认不用了
        if (cjRHrmresouce.toString().lastIndexOf(",") != -1) {
            cjRHrmresouce = new StringBuilder(cjRHrmresouce.substring(0, cjRHrmresouce.lastIndexOf(",")));
        }
        String[] cjRHrmresouceStrTwo = cjRHrmresouce.toString().split(",");
        List<String> cjRHrmresouceStrTwoList = new ArrayList<>(Arrays.asList(cjRHrmresouceStrTwo));
        cjRHrmresouceStrTwoList=cjRHrmresouceStrTwoList.stream().distinct().collect(Collectors.toList());
        cjRHrmresouce=new StringBuilder(StrUtil.join(",",cjRHrmresouceStrTwoList));
        return cjRHrmresouce;
    }
    public String getAllDqIdsList(String regionId){
        String sql="select region from uf_hotelinfo where id ='"+(StrUtil.isBlank(regionId)?"":regionId.replace("a","").replace("b",""))+"'";
        BaseBean baseBean=new BaseBean();
        baseBean.writeLog("getAllIdsListsql===>"+sql);
        RecordSet recordSet=new RecordSet();
        recordSet.execute(sql);
        if(recordSet.next()){

            return  recordSet.getString("region");
        }else {
            return "";
        }

    }
%>
<%
    BaseBean baseBean=new BaseBean();
    String adminUserId=request.getParameter("adminUserId");//多个用英文逗号隔开
    List<String> adminUserIdList= Arrays.asList(adminUserId.split(","));
    baseBean.writeLog("adminUserIdList====>"+ JSONUtil.toJsonStr(adminUserIdList));
    RecordSet recordSet=new RecordSet();
    List<Map<String,Object>> resultList=new ArrayList<>();
    if(!adminUserIdList.isEmpty()){
//        String sqlStr="select  id,rolename,adminname,managementregion from uf_rolegroup where adminname like '%"+adminUserId+"%'";
        String sqlStr="select  id,rolename,adminname,managementregion from uf_rolegroup  where find_in_set("+adminUserId+",adminname)";
        baseBean.writeLog("sqlStr===>"+sqlStr);
        recordSet.execute(sqlStr);

        while (recordSet.next()){
//            List<String> adminNameList=Arrays.asList(recordSet.getString("managementregion").split(","));
//            if(!adminNameList.contains(adminUserId)){
//                continue;
//            }
            Map<String,Object> paramMap=new HashMap<>();
            paramMap.put("id",recordSet.getString("id"));
            paramMap.put("rolename",recordSet.getString("rolename"));
            paramMap.put("adminname",recordSet.getString("adminname"));
            paramMap.put("managementregionSpan",getAllDqIdsList(recordSet.getString("managementregion")));
            StringBuilder stringBuilder=new StringBuilder();
            if(StrUtil.isNotBlank(paramMap.get("adminname")+"")){
                RecordSet peopleRecored=new RecordSet();
                peopleRecored.execute("select ID,lastname from hrmresource where"+Util.getSubINClause(paramMap.get("adminname")+"","id","in"));
                while (peopleRecored.next()){
                    stringBuilder.append(peopleRecored.getString("lastname")).append(",");

                }
            }
            if(StrUtil.isEmpty(stringBuilder.toString())&&StrUtil.isNotBlank(paramMap.get("adminname")+"")){
                RecordSet adminRecordSet=new RecordSet();
                adminRecordSet.execute("select lastname,id from HrmResourceManager where "+Util.getSubINClause(paramMap.get("adminname")+"","id","in"));
                while (adminRecordSet.next()){
                    stringBuilder.append(adminRecordSet.getString("lastname")).append(",");
                }

            }

            stringBuilder=distainStr(stringBuilder);
            paramMap.put("adminnameSpan",stringBuilder.toString());

            resultList.add(paramMap);
        }

    }
    response.setContentType("text/html;charset=utf-8");
    baseBean.writeLog("resultList======>"+JSONUtil.toJsonStr(resultList));
    response.getWriter().write(JSONUtil.toJsonStr(resultList));

%>
</body>
</html>
